using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class CircleHubPrevCtrl : HubPlugCtrlPrevPageBase
	{
		public delegate void ListItemClick(object sender, object object_0);
		private const string TAG = "CircleHubPrevCtrl";
		public bool bIsNew;
		private TimeLineObject timeLineObj;
		private static CircleHubPrevCtrl mCircleHubPrevCtrl;
		private bool mBIsFirstLoaded = true;
		public static DependencyProperty ItemObjectProperty = DependencyProperty.Register("ItemObject", typeof(SnsInfo), typeof(CircleHubPrevCtrl), new PropertyMetadata(null, new PropertyChangedCallback(CircleHubPrevCtrl.OnItemObjectPropertyChanged)));
		internal Grid LayoutRoot;
		internal CirclePagePicItem picCtrl;
		internal StackPanel newTipPanel;
		internal TextBlock NewTipTxt;
		internal EmojiText NickTxt;
		private bool _contentLoaded;
		public event CircleHubPrevCtrl.ListItemClick ItemClick;
		public SnsInfo ItemObject
		{
			get
			{
				return (SnsInfo)base.GetValue(CircleHubPrevCtrl.ItemObjectProperty);
			}
			set
			{
				base.SetValue(CircleHubPrevCtrl.ItemObjectProperty, value);
			}
		}
		public static CircleHubPrevCtrl getInstance()
		{
			if (CircleHubPrevCtrl.mCircleHubPrevCtrl == null)
			{
				CircleHubPrevCtrl.mCircleHubPrevCtrl = new CircleHubPrevCtrl();
			}
			return CircleHubPrevCtrl.mCircleHubPrevCtrl;
		}
		private CircleHubPrevCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
			this.picCtrl.DisableTouchEffect();
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
			this.bIsNew = false;
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private static void OnItemObjectPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == CircleHubPrevCtrl.ItemObjectProperty)
			{
				(dependencyObject_0 as CircleHubPrevCtrl).ItemObjectPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void ItemObjectPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.RefreshItem();
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
		}
		public void SetDefaultImg()
		{
			this.picCtrl.mDefaultImg = new BitmapImage(new Uri("/Source/Plugin/Sns/Common/Resource/newPicHint.png", 2));
			this.picCtrl.imgContent.set_Source(this.picCtrl.mDefaultImg);
			this.newTipPanel.set_Visibility(1);
		}
		private void RefreshItem()
		{
			if (this.ItemObject == null)
			{
				return;
			}
			this.NewTipTxt.set_Text(strings.WC_TIMELINE_NEWTIP);
			this.NickTxt.Text = ContactHelper.getDisplayName(this.ItemObject.strUserName, null);
			if (this.bIsNew)
			{
				this.newTipPanel.set_Visibility(0);
			}
			else
			{
				this.newTipPanel.set_Visibility(1);
			}
			this.picCtrl.mDefaultImg = new BitmapImage(new Uri("/Source/Plugin/Sns/Common/Resource/newPicHint.png", 2));
			this.timeLineObj = SnsInfoMgr.getTimeLine(this.ItemObject);
			if (this.timeLineObj != null && this.timeLineObj.content != null && this.timeLineObj.content.mediaList != null && this.timeLineObj.content.mediaList.get_Count() != 0)
			{
				int num = 0;
				Random random = new Random();
				if (this.timeLineObj.content.mediaList.get_Count() > 0)
				{
					num = random.Next() % this.timeLineObj.content.mediaList.get_Count();
				}
				TloMedia objMediaInfo = this.timeLineObj.content.mediaList.get_Item(num);
				this.picCtrl.imgContent.set_Stretch(3);
				this.picCtrl.ObjMediaInfo = objMediaInfo;
				return;
			}
			this.picCtrl.imgContent.set_Source(this.picCtrl.mDefaultImg);
		}
		public override void OnLanguaeChange()
		{
			base.OnLanguaeChange();
			this.NewTipTxt.set_Text(strings.WC_TIMELINE_NEWTIP);
		}
		public override void RefreshImg()
		{
			base.RefreshImg();
			if (this.timeLineObj != null && this.timeLineObj.content != null && this.timeLineObj.content.mediaList != null && this.timeLineObj.content.mediaList.get_Count() != 0)
			{
				int num = 0;
				Random random = new Random();
				if (this.timeLineObj.content.mediaList.get_Count() > 0)
				{
					num = random.Next() % this.timeLineObj.content.mediaList.get_Count();
				}
				TloMedia objMediaInfo = this.timeLineObj.content.mediaList.get_Item(num);
				this.picCtrl.imgContent.set_Stretch(3);
				this.picCtrl.ObjMediaInfo = objMediaInfo;
				return;
			}
			this.picCtrl.imgContent.set_Source(this.picCtrl.mDefaultImg);
		}
		public void UpdateCircleHubPreView(SnsInfo snsInfo)
		{
			if (snsInfo == null)
			{
				return;
			}
			if (CircleHubPrevCtrl.mCircleHubPrevCtrl != null)
			{
				CircleHubPrevCtrl.mCircleHubPrevCtrl.ItemObject = snsInfo;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/CircleHubPrevCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.picCtrl = (CirclePagePicItem)base.FindName("picCtrl");
			this.newTipPanel = (StackPanel)base.FindName("newTipPanel");
			this.NewTipTxt = (TextBlock)base.FindName("NewTipTxt");
			this.NickTxt = (EmojiText)base.FindName("NickTxt");
		}
	}
}
